home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_091 / adlrun / adldwim.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  197 lines

  1. #include <stdio.h>
  2.  
  3. #include "adltypes.h"
  4. #include "adlprog.h"
  5. #include "adlrun.h"
  6.  
  7.  
  8. int16
  9. dwimmer( rp, obj )
  10. int16
  11.     rp,
  12.     obj;
  13. {
  14.     bp = sp = NUMVAR;            /* Trim the stack */
  15.     push( 2 );                /* Push the stackdepth */
  16.     push( obj );            /* Push the object */
  17.     push( NUMVAR );            /* Push the bp */
  18.     ip = 0;
  19.     puship();                /* Push the ip */
  20.     if( !(ip = routspace[ rp ]) ) {
  21.     /* No dwimmer, so we fail. */
  22.     bp = sp = NUMVAR;
  23.     return 0;
  24.     }
  25.     runprog();                /* Run the dwimmer */
  26.     return stack[ NUMVAR ];        /* Return the retval */
  27. }
  28.  
  29.  
  30. dwimerror( n )
  31. int16
  32.     n;
  33. {
  34.     switch( n ) {
  35.     case 1 :
  36.         sayer( "You will have to be more specific.\n" );
  37.         break;
  38.     case 2 :
  39.         sayer( "You don't see anything like that.\n" );
  40.         break;
  41.     }
  42. }
  43.  
  44.  
  45. int16
  46. dwimadj( which, adj )
  47. int16
  48.     which,
  49.     adj;
  50. {
  51.     int16
  52.     i, tsave;
  53.  
  54.     tsave = 0;
  55.     for( i = 0; i < NUMOBJ; i++ ) {
  56.     if( objspace[ i ].adj == adj ) {
  57.         if( dwimmer( which, i ) ) {
  58.         if( tsave ) {
  59.             dwimerror( 1 );
  60.             return -1;
  61.         }
  62.         else
  63.             tsave = i;
  64.         }
  65.     }
  66.     }
  67.  
  68.     if( !tsave ) {
  69.     dwimerror( 2 );
  70.     return -1;
  71.     }
  72.     else
  73.     return tsave;
  74. }
  75.  
  76.  
  77. int16
  78. dwimnoun( which, noun )
  79. int16
  80.     which,
  81.     noun;
  82. {
  83.     int16
  84.     i, tsave;
  85.  
  86.     tsave = 0;
  87.     for( i = nounspace[ noun ]; i != 0; i = objspace[ i ].others ) {
  88.     if( dwimmer( which, i ) ) {
  89.         if( tsave ) {
  90.         dwimerror( 1 );
  91.         return -1;
  92.         }
  93.         else
  94.         tsave = i;
  95.     }
  96.     }
  97.  
  98.     if( !tsave ) {
  99.     dwimerror( 2 );
  100.     return -1;
  101.     }
  102.     else
  103.     return tsave;
  104. }
  105.  
  106.  
  107. dwimi()
  108. {
  109.     int16
  110.     t;
  111.  
  112.     if( SET_EXIT( 0 ) != 0 )
  113.     return -1;
  114.  
  115.     if( Inoun < 0 ) {
  116.     /* Copy the string index */
  117.     Iobj = Inoun;
  118.     return 0;
  119.     }
  120.     if( (Inoun == 0) && (Imod == 0) )
  121.     /* Preserve the old Iobj */
  122.     return 0;
  123.     if( Imod != 0 ) {
  124.     /* The player typed a modifier */
  125.     if( Inoun ) {
  126.         /* The player also typed a noun */
  127.         if( (Iobj = noun_exists( Imod, Inoun )) < 0 ) {
  128.         /* Oops - no such mod-noun pair */
  129.         dwimerror( 2 );
  130.         return -1;
  131.         }
  132.     }
  133.     else {
  134.         /* The player typed no noun */
  135.         if( (Iobj = dwimadj( _DWIMI, Imod )) < 0 )
  136.         /* Oops - the modifier wasn't sufficient */
  137.         return -1;
  138.     }
  139.     }
  140.     else {
  141.     /* The player typed a noun, but no modifier */
  142.     if( (t = noun_exists( 0, Inoun )) < 0 ) {
  143.         /* There is no unmodified object with noun Inoun */
  144.         if( (Iobj = dwimnoun( _DWIMI, Inoun )) < 0 )
  145.         /* Oops - the noun wasn't sufficient */
  146.         return -1;
  147.     }
  148.     else
  149.         /* Everything is fine. */
  150.         Iobj = t;
  151.     }
  152.     return 0;
  153. }
  154.  
  155.  
  156. dwimd()
  157. {
  158.     int16
  159.     i, t;
  160.  
  161.     if( SET_EXIT( 0 ) != 0 )
  162.     return -1;
  163.  
  164.     for( i = 0; i < NumDobj; i++ ) {
  165.     if( Dnoun[ i ] < 0 ) {        /* User typed a string */
  166.         Dobj[ i ] = Dnoun[ i ];
  167.         continue;
  168.     }
  169.     if( Dmod[ i ] != 0 ) {
  170.         /* The player typed a modifier */
  171.         if( Dnoun[ i ] ) {
  172.         /* The player typed a noun */
  173.         if( (Dobj[ i ] = noun_exists( Dmod[ i ], Dnoun[ i ] )) < 0 ) {
  174.             /* No such mod-noun pair exists */
  175.             dwimerror( 2 );
  176.             return -1;
  177.         }
  178.         }
  179.         else if( (Dobj[ i ] = dwimadj( _DWIMD, Dmod[ i ] )) < 0 ) {
  180.         return -1;
  181.         }
  182.     }
  183.     else if( (t = noun_exists( 0, Dnoun[ i ] )) < 0 ) {
  184.         /* An object with noun Dnoun[ i ] and mod 0 doesn't exist */
  185.         if( (Dobj[ i ] = dwimnoun( _DWIMD, Dnoun[ i ] )) < 0 ) {
  186.         return -1;
  187.         }
  188.     }
  189.     else
  190.         /* An object with noun Dnoun[ i ] and mod 0 DOES exist */
  191.         Dobj[ i ] = t;
  192.     }
  193.     return 0;
  194. }
  195.  
  196. /*** EOF adldwim.c ***/
  197.